/**
 * @author yz
 */
Mashuproom.components={};

Mashuproom.components.gmap= {
	id:"gmap",
	name:"Google Map",
	description:"Google Map",
	intro_url:"http://code.google.com/apis/maps/",
	variables:{
		ID:'gmap_gen_by_mr',
		Width:400,
		Height:400,
		Location_detect:true,
		Center_Latitude:30.3,
		Center_Longitude:120.117,
		Zoom_Level:10,
		ApiKey:'ABQIAAAAz-Al2CWfcvuZ8LDxd7C5mhQFqlSr-B2mSp3Xk9nKyoOFqHXCyBRxwiMwMTJIVmFc95laVWn8SZB89Q',//Key for our site.
		MapControl:true,
		MapTypeControl:true,
		LocalSearch:true,
		Keyword:''
	},
	getCodeString:function(config){
		var cstr = [];
		cstr.push('<div id="'+config.ID + '" style="width:'+config.Width+'px;height:'+config.Height+'px;background-color:#cde;">Loading map...</div>\n');
		cstr.push('<script language="javascript" type="text/javascript">\n');
		cstr.push(' Mashuproom.util.loadjs(["http://www.google.com/jsapi?key='+config.ApiKey+'"],mr_load_gmap);\n');
		if (config.LocalSearch) {
			cstr.push(' Mashuproom.util.loadcss(["http://www.google.com/uds/css/gsearch.css", "http://www.google.com/uds/solutions/localsearch/gmlocalsearch.css"]);\n');
		}
		cstr.push(' function mr_load_gmap(){google.load("maps","1",{"callback":');
		if(config.LocalSearch){
			cstr.push('mr_load_gsearch');
		}
		else{
			cstr.push('mr_addmap');
		}
		cstr.push('});}\n');
		if(config.LocalSearch){
			cstr.push(' function mr_load_gsearch(){google.load("search","1",{"callback":mr_load_localsearch});}\n');
			cstr.push(' function mr_load_localsearch(){Mashuproom.util.loadjs(["http://www.google.com/uds/solutions/localsearch/gmlocalsearch.js"],mr_addmap);}\n');
		}
		cstr.push(' function mr_addmap(){\n var map=new google.maps.Map2(document.getElementById("'+config.ID+'"));\n');
		if (config.Location_detect) {
			cstr.push(' map.setCenter(new google.maps.LatLng(google.loader.ClientLocation.latitude,google.loader.ClientLocation.longitude),'+config.Zoom_Level+');\n');
		}
		else {
			cstr.push(' map.setCenter(new google.maps.LatLng(' + config.Center_Latitude + ',' + config.Center_Longitude + '), ' + config.Zoom_Level + ');\n');
		}
		if (config.MapControl) {
			cstr.push(' map.addControl(new GSmallMapControl());\n');
		}
		if(config.MapTypeControl){
			cstr.push(' map.addControl(new GMapTypeControl());\n');
		}
		if(config.LocalSearch){
			cstr.push(' var localSearchControl = new google.maps.LocalSearch();\n');
			cstr.push(' map.addControl(localSearchControl, new google.maps.ControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(5, 5)));');
			cstr.push(' localSearchControl.execute("'+config.Keyword+'");');
		}
		cstr.push('}\n');
		cstr.push('</script>');
		return cstr.join("");
	},
	info:'*You should apply a apikey for your own site <a href="http://code.google.com/apis/maps/signup.html">here</a>.<br/>\
		For more information about Google map API, see the <a href="http://code.google.com/apis/maps/documentation/">\
		offical documentation</a>.<br/>'
	
};

Mashuproom.components.myflickr={
	id:"myflickr",
	name:"My flickr",
	description:"Get your flickr thumbs",
	intro_url:"http://www.flickr.com/services/api/",
	variables:{
		ID:'myflickr_gen_by_mr',
		Width:255,
		Height:170,
		Flickr_username:'mashuproom',
		DisplayCount:6,
		ApiKey:'b91688443c8b594ab83b04501ff8aa9b'
	},
	getCodeString:function(config){
		var cstr = [];
		cstr.push('<div id="'+config.ID+'" style="width:'+config.Width+'px;height:'+config.Height+'px;">Loading my flickr album...</div>\n');
		cstr.push('<style>#'+config.ID+' img{margin:5px;}</style>');
		cstr.push('<script language="javascript" type="text/javascript">\n');
		cstr.push('var mr_my_flickr_uid = "";\nvar mr_my_flickr_count = ' + config.DisplayCount + ';\nvar mr_my_flickr_uname="' + config.Flickr_username + '";\n');
		cstr.push('function mr_my_flickr(){\
	var find_uid_str = "http://api.flickr.com/services/rest/?method=flickr.people.findByUsername&format=json&api_key='+config.ApiKey+'&username="+mr_my_flickr_uname+"&jsoncallback=mr_my_flickr2";\n\
	Mashuproom.util.loadjs([find_uid_str]);}\n');
	
		cstr.push('function mr_my_flickr2(rsp){\n\
	mr_my_flickr_uid = rsp.user.id;\n\
	var find_photo_by_uid = "http://api.flickr.com/services/rest/?method=flickr.people.getPublicPhotos&format=json&api_key=b91688443c8b594ab83b04501ff8aa9b&user_id="+ mr_my_flickr_uid+"&per_page="+mr_my_flickr_count+"&jsoncallback=mr_my_flickr3";\n\
	Mashuproom.util.loadjs([find_photo_by_uid]);}\n');
	
		cstr.push('function mr_my_flickr3(rsp){\n\
	document.getElementById("'+config.ID+'").innerHTML="";\n\
	for(ip in rsp.photos.photo){\n\
	var p = rsp.photos.photo[ip];\n\
	var imlink = document.createElement("a");\
	imlink.href="http://www.flickr.com/photos/"+mr_my_flickr_uid+"/"+p.id;\n\
	imlink.target="blank";\n\
	var im = document.createElement("img");\n\
	im.src="http://farm"+p.farm+".static.flickr.com/"+p.server+"/"+p.id+"_"+p.secret+"_s.jpg";\n\
	im.alt=p.title;im.border=0;	imlink.appendChild(im);\n\
	document.getElementById("'+config.ID+'").appendChild(imlink);\n}\n}\n');
			
		cstr.push('mr_my_flickr();');
		
		cstr.push('</script>');
			
		return cstr.join("");
	},
	info:''
};
Mashuproom.components.gtranslate={
	id:"gtranslate",
	name:"Googe Translation",
	description:"Google Translation",
	intro_url:"http://code.google.com/apis/ajaxlanguage/",
	variables:{
		Width:200,
		Height:200
	},
	getCodeString:function(){
		return "";
	},
	info:'For more information about Google translation API, see the <a href="http://code.google.com/apis/ajaxlanguage/documentation/">\
	offical documentation</a>.<br/><div style="color:red;">Not available now</div>'
	
};
Mashuproom.components.gfeeds={
	id:"gfeeds",
	name:"Google Feeds",
	description:"Google Feeds",
	intro_url:"",
	variables:{

	},
	getCodeString:function(){
		return "";
	},
	info:'<div style="color:red;">Not available now</div>'
	
};
